/**
 * AfterSaleServiceImpl.java
 * Created at 2018-1-9
 * Created by zhanghailin
 * Copyright (C) 2018 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.app.aftersale.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.broadtext.app.aftersale.service.AfterSaleService;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.common.service.impl.EntityServiceImpl;
import com.broadtext.rms.system.dao.IWorkOrderDao;
import com.broadtext.rms.system.model.TmWorkOrder;

/**
 * <p>ClassName: AfterSaleServiceImpl</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2018-1-9</p>
 */
@Service("afterSaleService")
public class AfterSaleServiceImpl extends EntityServiceImpl<TmWorkOrder> implements AfterSaleService{
    
    @Autowired
    @Qualifier("workOrderDao")
    private IWorkOrderDao workOrderDao;
    
    @Autowired
    @Qualifier("workOrderDao")
    public void setEntityDao(EntityDao<TmWorkOrder> entityDao) {
        super.entityDao = entityDao;
    }

    /** (non-Javadoc)
     * <p>Title: getServiceRequestDataList</p>
     * <p>Description: 获取服务请求数据</p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getServiceRequestDataList(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> getServiceRequestDataList(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TmServiceRequest.getServiceRequestDataList", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }

    /** (non-Javadoc)
     * <p>Title: getUserIdByLoginName</p>
     * <p>Description: </p>
     * @param loginName
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getUserIdByLoginName(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public String getUserIdByLoginName(String loginName) {
        List<String> list = new ArrayList<String>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TmServiceRequest.getUserIdByLoginName", loginName);
            if(list!=null&&list.size()>0&&list.get(0)!=null){
                return list.get(0);
            }
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }

    /** (non-Javadoc)
     * <p>Title: getWorkOrderDataList</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getWorkOrderDataList(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> getWorkOrderDataList(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TmWorkOrder.findWorkOrderList", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }

    /** (non-Javadoc)
     * <p>Title: getAppendOfTodayData</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getAppendOfTodayData(java.util.Map)
     */
    @Override
    public List<Object> getAppendOfTodayData(Map<String, Object> params) {
        return null;
    }

    /** (non-Javadoc)
     * <p>Title: getRequestCount</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getRequestCount(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> getRequestCount(Map<String, Object> params) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("notProcessedCount", 0);
        data.put("confirmedCount", 0);
        data.put("processingCount", 0);
        data.put("solvedCount", 0);
        data.put("closedCount", 0);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TmWorkOrder.getRequestCount", params);
            if(list!=null&&list.size()>0){
                for (Map<String, Object> map : list) {
                    if("1".equals(String.valueOf(map.get("status")))){
                        data.put("notProcessedCount", map.get("count"));
                    }
                    if("2".equals(String.valueOf(map.get("status")))){
                        data.put("confirmedCount", map.get("count"));
                    }
                    if("3".equals(String.valueOf(map.get("status")))){
                        data.put("processingCount", map.get("count"));
                    }
                    if("4".equals(String.valueOf(map.get("status")))){
                        data.put("solvedCount", map.get("count"));
                    }
                    if("5".equals(String.valueOf(map.get("status")))){
                        data.put("closedCount", map.get("count"));
                    }
                }
            }
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return data;
    }

    /** (non-Javadoc)
     * <p>Title: getServicePlanCount</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getServicePlanCount(java.util.Map)
     */
    @Override
    public Long getServicePlanCount(Map<String, Object> params) {
        Long count = this.workOrderDao.getServicePlanCount(params);
        return count;
    }

    /** (non-Javadoc)
     * <p>Title: getServiceRequestCount</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getServiceRequestCount(java.util.Map)
     */
    @Override
    public Long getServiceRequestCount(Map<String, Object> params) {
        Long count = this.workOrderDao.getServiceRequestCount(params);
        return count;
    }

    /** (non-Javadoc)
     * <p>Title: getWorkOrderHistoryList</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.app.aftersale.service.AfterSaleService#getWorkOrderHistoryList(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> getWorkOrderHistoryList(Map<String, Object> params) {
        List<Object> list = new ArrayList<Object>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.TmWoHistory.getWorkOrderHistory2", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }


}
